package com.sanchunhui.psc.common

import android.app.Application
import android.content.Context
import com.alibaba.android.arouter.launcher.ARouter
import com.sanchunhui.psc.data.protocol.UserInfo
import com.sanchunhui.psc.injection.component.AppComponent
import com.sanchunhui.psc.injection.component.DaggerAppComponent
import com.sanchunhui.psc.injection.module.AppModule


/*
    Application 基类
 */
open class BaseApplication : Application() {

    lateinit var appComponent: AppComponent

    override fun onCreate() {
        super.onCreate()

//        instance = this
        mUser.loginId = -1 // 未登录用户id=-1

        initAppInjection()

        context = this

        //ARouter初始化
        ARouter.openLog()    // 打印日志
        ARouter.openDebug()
        ARouter.init(this)
    }

    /*
        Application Component初始化
     */
    private fun initAppInjection() {
        appComponent = DaggerAppComponent.builder().appModule(AppModule(this)).build()
    }

    /*
        全局伴生对象
     */
    companion object {
        lateinit var context: Context
//        lateinit var instance : BaseApplication
        var mUser : UserInfo = UserInfo()
    }
}
